package com.example.shangjiba;

import android.os.Bundle;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

/**
 * 新闻详情页
 */
public class DetailActivity extends AppCompatActivity {

    private TextView tvDetailTitle;
    private TextView tvDetailTime;
    private TextView tvDetailDescription;
    private TextView tvDetailContent;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_detail);

        // 初始化视图
        tvDetailTitle = findViewById(R.id.tv_detail_title);
        tvDetailTime = findViewById(R.id.tv_detail_time);
        tvDetailDescription = findViewById(R.id.tv_detail_description);
        tvDetailContent = findViewById(R.id.tv_detail_content);

        // 获取传递过来的数据
        NewsItem newsItem = (NewsItem) getIntent().getSerializableExtra("news_item");

        if (newsItem != null) {
            // 显示数据
            tvDetailTitle.setText(newsItem.getTitle());
            tvDetailTime.setText(newsItem.getTime());
            tvDetailDescription.setText(newsItem.getDescription());
            tvDetailContent.setText(newsItem.getContent());
        }

        // 设置返回按钮
        if (getSupportActionBar() != null) {
            getSupportActionBar().setDisplayHomeAsUpEnabled(true);
            getSupportActionBar().setTitle("新闻详情");
        }
    }

    @Override
    public boolean onSupportNavigateUp() {
        finish();
        return true;
    }
}
